package org.sys.transporttrainsys.service;

import org.sys.transporttrainsys.entity.OrganizationType;
import org.sys.transporttrainsys.repository.OrganizationTypeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrganizationTypeService {

    @Autowired
    private OrganizationTypeRepository organizationTypeRepository;

    public List<OrganizationType> getAllOrganizationTypes() {
        return organizationTypeRepository.findAll();
    }

    public List<OrganizationType> searchOrganizationTypesByName(String name) {
        return organizationTypeRepository.findByTypeNameContainingIgnoreCase(name);
    }

    public OrganizationType createOrganizationType(OrganizationType organizationType) {
        return organizationTypeRepository.save(organizationType);
    }

    public OrganizationType updateOrganizationType(Long id, OrganizationType organizationType) {
        organizationType.setId(id);
        return organizationTypeRepository.save(organizationType);
    }

    public void deleteOrganizationType(Long id) {
        organizationTypeRepository.deleteById(id);
    }
}